<?php

namespace App\Api\Logic;

use App\Api\Logic\Validate\GoodsGroupValidate;
use App\Exceptions\ValidationException;
use App\Helpers\ResponseEnum;
use App\Models\TongGoodsGroup;
use App\Models\TongUserAddress;

class GoodsGroupLogic extends BaseLogic
{
    /**
     * 获取实力对象
     * @return GoodsGroupValidate
     */
    private function getValidate():GoodsGroupValidate{
        return  new GoodsGroupValidate();
    }


    public function getGroupGoodsInfo(array $data)
    {
        $validate = $this->getValidate();
        if(!$validate->scene('getGroupGoodsInfo')->check($data)){
            throw new ValidationException(ResponseEnum::HTTP_ERROR,$validate->getError());
        }
    }

    /**
     * 创建套餐订单
     * @param array $params
     * @return void
     */
    public function addGroupOrder(array $params)
    {
        $validate = $this->getValidate();
        if(!$validate->scene('addGroupOrder')->check($params)){
            throw new ValidationException(ResponseEnum::HTTP_ERROR,$validate->getError());
        }
        if($params['u_id']!=5067){
            throw new ValidationException(ResponseEnum::HTTP_ERROR,'系统升级，请先核对自己的数据');
        }
        $group_goods_query = TongGoodsGroup::query()->where('id',$params['goods_group_id']);
        if(!$group_goods_query->exists()){
            throw new ValidationException(ResponseEnum::HTTP_ERROR,'商品不存在');
        }

        $result = TongUserAddress::query()->where('id',$params['address_id'])
            ->where('u_id',$params['u_id'])->exists();
        if(!$result){
            throw new ValidationException(ResponseEnum::HTTP_ERROR,'地址错误不存在');
        }
    }
}
